#include <iostream>
#include <string.h>
#include <set>
#include <vector>
using namespace std;

long N, C;
long weights[2000];

long ans = 0;
long a[1000] = {0};
struct Node
{
    set<long> nums;
    long sum_w = 0;
    vector<Node> sons;
    long id;
    int deepth = 0;
};

set<set<long>> been;
long been1[2000] = {0};
int max_deepth = 0;
void dfs(Node now)
{
    been1[now.id] = 1;
    been.insert(now.nums);
    if(now.sum_w > ans && now.sum_w <= C)
    {    ans = now.sum_w;}
    for(long i = 0; i < N; i++)
    {
        if(now.sum_w + weights[i] <= C)
        {
            Node temp;

            temp.id = i;
            temp.sum_w = now.sum_w + weights[i];
            if(been1[temp.id] == 0 && temp.sum_w + a[temp.id] >= ans)
                dfs(temp);
        }
    }

    // for(long i = 0 ; i < now.sons.size(); i++)
    //     dfs(now.sons[i]);

    been1[now.id] = 0;
}

int main()
{
    memset(weights, 0, sizeof(weights));

    cin >> N >> C;
    for(long i = 0; i < N; i++)
    {
        cin >> weights[N - i - 1];
        a[N - i - 1] += weights[N - i] + a[N - i];
    }    

    Node now;
    now.nums.insert(-1);
    been.insert(now.nums);
    for(long i = 0; i < N; i++)
    {
        if(now.sum_w + weights[i] <= C)
        {
            Node temp;
            temp.nums = now.nums;
            temp.nums.insert(i);
            temp.id = i;
            temp.deepth = 1;
            temp.sum_w = now.sum_w + weights[i];
            if(been.count(temp.nums) == 0)
                now.sons.push_back(temp);
        }
    }

    for(long i = 0 ; i < now.sons.size(); i++)
        dfs(now.sons[i]);


    cout  << ans;
}